package cn.kingyang.yiyi.ui.fragment;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.view.View;

import com.jtech.listener.OnItemClickListener;
import com.jtech.view.JRecyclerView;
import com.jtech.view.RecyclerHolder;
import com.jtech.view.RefreshLayout;

import java.util.List;

import butterknife.BindView;
import cn.kingyang.yiyi.R;
import cn.kingyang.yiyi.mvp.model.bean.HttpData;
import cn.kingyang.yiyi.mvp.model.bean.NobleVideo;
import cn.kingyang.yiyi.mvp.presenter.NoblePresenter;
import cn.kingyang.yiyi.mvp.view.NobleView;
import cn.kingyang.yiyi.ui.activity.VideoInfoActivity;
import cn.kingyang.yiyi.ui.adapter.NobleVideoAdapter;
import cn.kingyang.yiyi.ui.fragment.base.BaseMainFragment;
import cn.kingyang.yiyi.utils.AppUtil;


/**
 * Created by Administrator on 2017/2/28.
 */

public class NobleFragment extends BaseMainFragment<NobleView, NoblePresenter> implements NobleView, RefreshLayout.OnRefreshListener, OnItemClickListener {
    @BindView(R.id.noble_video_jr)
    JRecyclerView mVideoJRV;//
    private NobleVideoAdapter mVideoAdapter;//
    @BindView(R.id.refreshlayout)
    RefreshLayout refreshlayout;//下拉刷新组件
    public static NobleFragment newInstance() {
        return new NobleFragment();
    }


    @Override
    protected NoblePresenter getPresenter() {
        return new NoblePresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_noble;
    }

    @Override
    protected void initView(View view) {
        mVideoAdapter =new NobleVideoAdapter(_mActivity);
        mVideoJRV.setLayoutManager(new GridLayoutManager(getActivity(),1));
        mVideoJRV.setAdapter(mVideoAdapter);
        mVideoJRV.setOnItemClickListener(this);
        refreshlayout.setOnRefreshListener(this);
        refreshlayout.startRefreshing();
    }



    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void onError(Throwable t) {

    }




    @Override
    public void onRefresh() {
        mPresenter.getNobleInfo();
    }

    @Override
    public void onItemClick(RecyclerHolder recyclerHolder, View view, int i) {
        //进入视频详情页？
        //暂时弹出popupwindow
//        AppUtil.showPopupWindow(_mActivity,getView());
        Intent intent=new Intent(_mActivity, VideoInfoActivity.class);
        intent.putExtra("data",  mVideoAdapter.getRealDatas().get(i));
        intent.putExtra("title",  mVideoAdapter.getRealDatas().get(AppUtil.getRandom(0,mVideoAdapter.getRealDatas().size())).getTitle());
        intent.putExtra("pic",  mVideoAdapter.getRealDatas().get(AppUtil.getRandom(0,mVideoAdapter.getRealDatas().size())).getThumb());
        intent.putExtra("title1",  mVideoAdapter.getRealDatas().get(AppUtil.getRandom(0,mVideoAdapter.getRealDatas().size())).getTitle());
        intent.putExtra("pic1",  mVideoAdapter.getRealDatas().get(AppUtil.getRandom(0,mVideoAdapter.getRealDatas().size())).getThumb());
//        intent.putExtra("url",mVideoAdapter.getRealDatas().get(i).getVideourl());
        startActivity(intent);
    }

    @Override
    public void doNobleInfo(HttpData<List<NobleVideo>> data) {
        mVideoAdapter.setDatas(data.getData());
        refreshlayout.refreshingComplete();
    }
}
